<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/extras/spring-security">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>面试历史 - SimpleHire</title>
    
    <!-- Bootstrap CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- Bootstrap Icons -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css" rel="stylesheet">
    
    <style>
        :root {
            --primary-color: #2c3e50;
            --secondary-color: #3498db;
            --accent-color: #e74c3c;
            --success-color: #27ae60;
            --warning-color: #f39c12;
            --light-bg: #f8f9fa;
            --card-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        }

        body {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }

        .navbar {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            box-shadow: var(--card-shadow);
        }

        .navbar-brand {
            font-weight: bold;
            color: var(--primary-color) !important;
            font-size: 1.5rem;
        }

        .main-container {
            margin-top: 2rem;
            margin-bottom: 2rem;
        }

        .history-card {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            border: none;
            border-radius: 20px;
            box-shadow: var(--card-shadow);
            overflow: hidden;
        }

        .card-header {
            background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
            color: white;
            border: none;
            padding: 2rem;
        }

        .interview-item {
            background: white;
            border-radius: 15px;
            padding: 1.5rem;
            margin-bottom: 1rem;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
            transition: all 0.3s ease;
            border-left: 4px solid var(--secondary-color);
        }

        .interview-item:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
        }

        .score-badge {
            font-size: 1.1rem;
            font-weight: bold;
            padding: 0.5rem 1rem;
            border-radius: 25px;
        }

        .score-excellent {
            background: linear-gradient(135deg, #27ae60, #2ecc71);
            color: white;
        }

        .score-good {
            background: linear-gradient(135deg, #3498db, #5dade2);
            color: white;
        }

        .score-average {
            background: linear-gradient(135deg, #f39c12, #f7dc6f);
            color: white;
        }

        .score-poor {
            background: linear-gradient(135deg, #e74c3c, #ec7063);
            color: white;
        }

        .btn-action {
            border-radius: 25px;
            padding: 0.5rem 1.5rem;
            font-weight: 500;
            transition: all 0.3s ease;
        }

        .btn-primary {
            background: linear-gradient(135deg, var(--secondary-color), #5dade2);
            border: none;
        }

        .btn-primary:hover {
            transform: translateY(-1px);
            box-shadow: 0 4px 8px rgba(52, 152, 219, 0.3);
        }

        .btn-danger {
            background: linear-gradient(135deg, var(--accent-color), #ec7063);
            border: none;
        }

        .btn-danger:hover {
            transform: translateY(-1px);
            box-shadow: 0 4px 8px rgba(231, 76, 60, 0.3);
        }

        .pagination {
            justify-content: center;
            margin-top: 2rem;
        }

        .page-link {
            border-radius: 25px;
            margin: 0 0.2rem;
            border: none;
            color: var(--secondary-color);
        }

        .page-item.active .page-link {
            background: linear-gradient(135deg, var(--secondary-color), #5dade2);
            border: none;
        }

        .empty-state {
            text-align: center;
            padding: 3rem;
            color: #6c757d;
        }

        .empty-state i {
            font-size: 4rem;
            margin-bottom: 1rem;
            opacity: 0.5;
        }

        .alert {
            border-radius: 15px;
            border: none;
            margin-bottom: 1.5rem;
        }

        .interview-meta {
            font-size: 0.9rem;
            color: #6c757d;
        }

        .filename-badge {
            background: #e9ecef;
            color: #495057;
            padding: 0.25rem 0.75rem;
            border-radius: 15px;
            font-size: 0.85rem;
        }
    </style>
</head>
<body>
    <!-- Navigation -->
    <nav class="navbar navbar-expand-lg navbar-light">
        <div class="container">
            <a class="navbar-brand" href="/">
                <i class="bi bi-robot me-2"></i>SimpleHire
            </a>
            
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
                <span class="navbar-toggler-icon"></span>
            </button>
            
            <div class="collapse navbar-collapse" id="navbarNav">
                <ul class="navbar-nav me-auto">
                    <li class="nav-item">
                        <a class="nav-link" href="/interview">
                            <i class="bi bi-chat-dots me-1"></i>面试
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link active" href="/interview/history">
                            <i class="bi bi-clock-history me-1"></i>历史记录
                        </a>
                    </li>
                </ul>
                
                <ul class="navbar-nav">
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown">
                            <i class="bi bi-person-circle me-1"></i>
                            <span sec:authentication="name">用户</span>
                        </a>
                        <ul class="dropdown-menu">
                            <li><a class="dropdown-item" href="/interview/history">
                                <i class="bi bi-clock-history me-2"></i>面试历史
                            </a></li>
                            <li><hr class="dropdown-divider"></li>
                            <li><a class="dropdown-item" href="/logout">
                                <i class="bi bi-box-arrow-right me-2"></i>退出登录
                            </a></li>
                        </ul>
                    </li>
                </ul>
            </div>
        </div>
    </nav>

    <!-- Main Content -->
    <div class="container main-container">
        <div class="row justify-content-center">
            <div class="col-lg-10">
                <div class="card history-card">
                    <div class="card-header text-center">
                        <h2 class="mb-0">
                            <i class="bi bi-clock-history me-3"></i>面试历史记录
                        </h2>
                        <p class="mb-0 mt-2 opacity-75">查看您的所有面试记录和评估结果</p>
                    </div>
                    
                    <div class="card-body">
                        <!-- Success/Error Messages -->
                        <div th:if="${message}" class="alert alert-success alert-dismissible fade show" role="alert">
                            <i class="bi bi-check-circle me-2"></i>
                            <span th:text="${message}"></span>
                            <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
                        </div>
                        
                        <div th:if="${error}" class="alert alert-danger alert-dismissible fade show" role="alert">
                            <i class="bi bi-exclamation-triangle me-2"></i>
                            <span th:text="${error}"></span>
                            <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
                        </div>

                        <!-- Interview History List -->
                        <div th:if="${historyPage != null and historyPage.hasContent()}">
                            <div th:each="result : ${historyPage.content}" class="interview-item">
                                <div class="row align-items-center">
                                    <div class="col-md-8">
                                        <div class="d-flex align-items-center mb-2">
                                            <h5 class="mb-0 me-3">
                                                <i class="bi bi-file-text me-2"></i>
                                                面试记录 #<span th:text="${result.id}"></span>
                                            </h5>
                                            <span th:if="${result.resumeFilename}" 
                                                  class="filename-badge" 
                                                  th:text="${result.resumeFilename}"></span>
                                        </div>
                                        
                                        <div class="interview-meta">
                                            <i class="bi bi-calendar me-1"></i>
                                            <span th:text="${#temporals.format(result.createdAt, 'yyyy-MM-dd HH:mm')}"></span>
                                            <span class="ms-3">
                                                <i class="bi bi-clock me-1"></i>
                                                <span th:text="${#temporals.format(result.updatedAt, 'yyyy-MM-dd HH:mm')}"></span>
                                            </span>
                                        </div>
                                        
                                        <div class="mt-2" th:if="${result.resumeText}">
                                            <small class="text-muted">
                                                <i class="bi bi-text-paragraph me-1"></i>
                                                简历摘要: 
                                                <span th:text="${#strings.abbreviate(result.resumeText, 100)}"></span>
                                            </small>
                                        </div>
                                    </div>
                                    
                                    <div class="col-md-4 text-end">
                                        <div class="mb-3">
                                            <span th:if="${result.score != null}" 
                                                  class="score-badge"
                                                  th:classappend="${result.score >= 90} ? 'score-excellent' : 
                                                                 (${result.score >= 80} ? 'score-good' : 
                                                                 (${result.score >= 60} ? 'score-average' : 'score-poor'))">
                                                <i class="bi bi-star-fill me-1"></i>
                                                <span th:text="${result.score}"></span>分
                                            </span>
                                            <span th:unless="${result.score != null}" class="badge bg-secondary">
                                                <i class="bi bi-hourglass-split me-1"></i>未完成
                                            </span>
                                        </div>
                                        
                                        <div class="btn-group" role="group">
                                            <a th:href="@{/interview/result/{id}(id=${result.id})}" 
                                               class="btn btn-primary btn-action btn-sm"
                                               th:if="${result.score != null}">
                                                <i class="bi bi-eye me-1"></i>查看结果
                                            </a>
                                            <a th:href="@{/interview/questions/{id}(id=${result.id})}" 
                                               class="btn btn-primary btn-action btn-sm"
                                               th:unless="${result.score != null}">
                                                <i class="bi bi-play-circle me-1"></i>继续面试
                                            </a>
                                            
                                            <form th:action="@{/interview/delete/{id}(id=${result.id})}" 
                                                  method="post" 
                                                  style="display: inline;"
                                                  onsubmit="return confirm('确定要删除这条面试记录吗？')">
                                                <button type="submit" class="btn btn-danger btn-action btn-sm">
                                                    <i class="bi bi-trash me-1"></i>删除
                                                </button>
                                            </form>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            
                            <!-- Pagination -->
                            <nav th:if="${historyPage.totalPages > 1}">
                                <ul class="pagination">
                                    <li class="page-item" th:classappend="${historyPage.first} ? 'disabled'">
                                        <a class="page-link" th:href="@{/interview/history(page=${currentPage - 1})}">
                                            <i class="bi bi-chevron-left"></i>
                                        </a>
                                    </li>
                                    
                                    <li th:each="pageNum : ${#numbers.sequence(0, historyPage.totalPages - 1)}" 
                                        class="page-item" 
                                        th:classappend="${pageNum == currentPage} ? 'active'">
                                        <a class="page-link" 
                                           th:href="@{/interview/history(page=${pageNum})}" 
                                           th:text="${pageNum + 1}"></a>
                                    </li>
                                    
                                    <li class="page-item" th:classappend="${historyPage.last} ? 'disabled'">
                                        <a class="page-link" th:href="@{/interview/history(page=${currentPage + 1})}">
                                            <i class="bi bi-chevron-right"></i>
                                        </a>
                                    </li>
                                </ul>
                            </nav>
                        </div>
                        
                        <!-- Empty State -->
                        <div th:unless="${historyPage != null and historyPage.hasContent()}" class="empty-state">
                            <i class="bi bi-inbox"></i>
                            <h4>暂无面试记录</h4>
                            <p class="text-muted">您还没有进行过任何面试，开始您的第一次AI面试吧！</p>
                            <a href="/interview" class="btn btn-primary btn-action">
                                <i class="bi bi-plus-circle me-2"></i>开始面试
                            </a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Bootstrap JS -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>